def prime(a):
    t = True
    for q in range(2, int(a ** 0.5)+1):
        if a % q == 0:
            t = False
            break
    return t

b = int(input())
if b < 1000 or b > 9999:
    print(0)
else:
    gpt = str(b)
    m = 0
    for h in range(len(gpt)):
        for i in range(h+1, len(gpt)+1):
            num = int(gpt[h:i])
            if prime(num):
                m = max(m, num)
    print(m)